{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from PIL import Image"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "# 打开图片文件\n",
    "image_path = 'your_image_path.jpg'  # 替换为你的图片路径\n",
    "image = Image.open(image_path)\n",
    "\n",
    "# 确保图片是RGB模式\n",
    "image = image.convert('RGB')\n",
    "\n",
    "# 定义Patch的大小\n",
    "patch_size = 16\n",
    "\n",
    "# 计算图片的宽度和高度\n",
    "width, height = image.size\n",
    "\n",
    "# 计算需要分割的Patch的行数和列数\n",
    "num_patches_y = height // patch_size\n",
    "num_patches_x = width // patch_size\n",
    "\n",
    "# 分割图片为Patch序列\n",
    "patches = []\n",
    "for y in range(0, num_patches_y):\n",
    " for x in range(0, num_patches_x):\n",
    "     # 裁剪图片为16x16的Patch\n",
    "     patch = image.crop((x * patch_size, y * patch_size, (x + 1) * patch_size, (y + 1) * patch_size))\n",
    "     patches.append(patch)\n",
    "\n",
    "# 打印Patch的数量\n",
    "print(f'Total patches: {len(patches)}')\n",
    "\n",
    "# 可选：展示所有的Patch\n",
    "# for i, patch in enumerate(patches):\n",
    "#     patch.show(f'Patch {i}')"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
